<template>
    <h2>添加等级权益信息</h2>
<table>
    <tr>
        <td>会员等级</td>
        <td>
            <select v-model="info.Rank_Id">
                <option :value="0">--请选择--</option>
                <option v-for="item in RankInfo" :value="item.Rank_Id">{{ item.Rank_Name }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>会员权益</td>
        <td>
            <select v-model="info.MR_Id">
                <option :value="0">--请选择--</option>
                <option v-for="item in RightsInfo" :value="item.MR_Id">{{ item.MR_Name }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="button" value="添加" class="btn btn-success" @click="SaveData">
        </td>
    </tr>
</table>


</template>
<script setup lang="ts">

import axios from 'axios';
import { onMounted,ref } from 'vue';


const info=ref({

    MR_Id:0,
    Rank_Id:0

})

//保存
const SaveData=()=>{

    axios.post('https://localhost:7153/api/MemberRights/AddRankRights',info.value)
    .then(res=>{
        if(res.data==-1){
            alert("数据已经存在");
        }
        else if(res.data>0){
            alert("添加成功");
        }
        else{
            alert("添加失败");
        }
    })



}


const RankInfo=ref([{
    Rank_Id:0,
    Rank_Name:""


}])

const RightsInfo=ref([{

    MR_Id:0,
    MR_Name:""

}])


onMounted(()=>{

    LoadRank();
    LoadRights();
})

const LoadRights=()=>{

    axios.get('https://localhost:7153/api/MemberRights/ShowRightaInfo')
    .then(res=>{
        RightsInfo.value=res.data


    })
    


}
 
const LoadRank=()=>{

    axios.get('https://localhost:7153/api/MemberRights/ShowRankInfo')
    .then(res=>{
        RankInfo.value=res.data
    })


}




</script>